import SCModal from '../../components/pickCity/SCModal'
import React from 'react';
import {Form, Row, Col, Button, Dropdown, Menu, Icon, message, Input} from 'antd';
import {injectIntl} from 'react-intl';
import {sessionManager} from '../../utils/sessionStorage';
import axios from "axios/index";

const FormItem = Form.Item;
const createForm = Form.create;

class ModifyStub extends React.Component {
    constructor(props) {
        super(props);
        this.common = this.props.intl.messages.common;
        this.state = {};
    }

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((errors, values) => {
            if (!!errors) {
                console.log('Errors in form!!!');
                return;
            }
            const selectStuGroup = sessionManager.get('selectStuGroup');
            values.stubGroupId=selectStuGroup.id;
            axios.get('/api/stubGroup/name/update', {params: values}).then(res => {
                if(res&&res.code==200){
                    this.props.handleCancel();
                    this.props.freshGrid()
                }
            })
        });
    }

    render() {
        const {visible, handleCancel} = this.props;
        const {getFieldDecorator} = this.props.form;
        const selectStuGroup = sessionManager.get('selectStuGroup');
        return (
            <SCModal visible={visible} handleCancel={handleCancel} width={500}>
                <form layout="vertical" form={this.props.form}>
                    <FormItem label={'桩群名称(修改名称后，10分钟后生效)'}>
                        {getFieldDecorator('name', {
                            rules: [
                                {required: true, message: this.common.required}
                            ],
                            initialValue: selectStuGroup.name
                        })(
                            <Input/>
                        )}
                    </FormItem>
                    <FormItem>
                        <Button className="ant-btn-84" type="primary" onClick={this.handleSubmit}>{'确定'}</Button>
                    </FormItem>
                </form>
            </SCModal>
        )
    }
}

ModifyStub = createForm()(ModifyStub);
export default injectIntl(ModifyStub)
